Skip to content

Add Rust template#11

Merged
lucperkins merged 8 commits intomainfrom
rust-template
Oct 24, 2025
Merged

Add Rust template#11
lucperkins merged 8 commits intomainfrom
rust-template

Conversation

@lucperkins
Copy link
Member

@lucperkins lucperkins commented Oct 10, 2025

  • First iteration of template
  • Add Rust template checks

Summary by CodeRabbit

  • New Features

    • Added a Rust project template with per-system dev shells, buildable package, and a starter app that prints a greeting.
    • Enabled direnv-based environment loading for the Rust template.
    • Added .gitignore entries for Rust and Nix artifacts.
  • Chores

    • CI now performs explicit NixOS and Rust template builds and prints clearer status logs during checks.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 10, 2025

Walkthrough

Adds a new Rust flake template under rust/, registers it in outputs.templates, updates CI to perform a NixOS toplevel build and explicit Rust template checks (resolve system, build dev shell and package), and adds direnv and gitignore entries for the Rust template.

Changes

Cohort / File(s) Summary
CI workflow updates
.github/workflows/ci.yaml
Adds NixOS toplevel build invocation with echo logs; adds a "Check Rust template" step that evals builtins.currentSystem, builds .#devShells.<system>.default and .#packages.<system>.default, and logs before/after.
Flake templates registry
flake.nix
Adds rust entry under outputs.templates with description, path = ./rust, and welcomeText.
Rust template scaffolding
rust/.envrc, rust/.gitignore, rust/Cargo.toml, rust/flake.nix, rust/src/main.rs
Introduces Rust template: use flake direnv, gitignore for /target/ and result*, Cargo.toml manifest, rust/flake.nix providing per-system devShells and packages (with RUST_SRC_PATH and shellHook), and minimal main.rs.
Minor comment updates
default/flake.nix, nix-darwin/flake.nix, nixos/flake.nix
Comment text updated to mention unstable usage notes for nixpkgs/nix-darwin/Determinate; no functional changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant CI as CI Workflow
  participant Nix as nix
  participant Repo as repository (flake)

  Note over CI: Check NixOS template
  CI->>Nix: nix build .#nixosConfigurations.<name>.config.system.build.toplevel
  Nix-->>CI: toplevel build result

  Note over CI: Check Rust template
  CI->>Nix: nix eval --raw --expr builtins.currentSystem
  Nix-->>CI: "<system>"
  CI->>Repo: nix build .#devShells.<system>.default
  Repo-->>CI: devShell derivation
  CI->>Repo: nix build .#packages.<system>.default
  Repo-->>CI: package derivation
Loading
sequenceDiagram
  autonumber
  participant Dev as Developer
  participant Direnv as direnv
  participant Flake as rust/flake.nix
  participant Nixpkgs as nixpkgs

  Dev->>Direnv: enter rust/ (use flake)
  Direnv->>Flake: load devShells.<system>.default
  Flake->>Nixpkgs: import with config.allowUnfree = true
  Flake->>Dev: shellHook prints message, sets RUST_SRC_PATH

  Dev->>Flake: nix build .#packages.<system>.default
  Flake-->>Dev: package build/result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • edolstra
  • grahamc

Poem

In flakes I hop and nibble code,
Cargo crates along the road.
CI hums, checks shell and crate,
Dev shell warms my velvet pate.
Hello world — a tiny crate of cheer. 🐇🦀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title “Add Rust template” succinctly and accurately captures the main change of introducing a new Rust project template and is clear and concise for readers scanning the project history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rust-template

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc1c325 and 9807c99.

📒 Files selected for processing (1)
  • rust/flake.nix (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • rust/flake.nix
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: checks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
rust/flake.nix (1)

44-46: Consider using the computed version variable.

A git-based version is computed at line 45 but never used. The package build at line 80 uses meta.version from Cargo.toml instead, which is the static "0.1.0" value.

If you want git-based versioning for development builds, apply this diff:

       packages = forEachSupportedSystem (
         { pkgs }:
         {
           default = ((inputs.crane.mkLib pkgs).overrideToolchain pkgs.rustToolchain).buildPackage {
             pname = meta.name;
-            inherit (meta) version;
+            inherit version;
             src = builtins.path {
               name = "${meta.name}-source";
               path = ./.;
             };
           };
         }
       );

Alternatively, if you prefer using Cargo.toml version exclusively, you can remove the unused version variable at line 45.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7ffd1e5 and 389a5dc.

⛔ Files ignored due to path filters (1)
  • rust/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • .github/workflows/ci.yaml (1 hunks)
  • flake.nix (1 hunks)
  • rust/.envrc (1 hunks)
  • rust/.gitignore (1 hunks)
  • rust/Cargo.toml (1 hunks)
  • rust/flake.nix (1 hunks)
  • rust/src/main.rs (1 hunks)
🔇 Additional comments (10)
rust/.gitignore (1)

1-5: LGTM!

Standard ignore patterns for Rust and Nix artifacts are correctly configured.

rust/src/main.rs (1)

1-3: LGTM!

Minimal hello world program is appropriate for a template starting point.

.github/workflows/ci.yaml (1)

49-56: LGTM!

The CI step correctly builds both the dev shell and package for the Rust template. The system detection and build commands are appropriate for validating the template functionality.

rust/flake.nix (5)

1-14: LGTM!

The flake inputs are well-structured with appropriate sources for nixpkgs, Rust toolchain (fenix), and build system (crane). The input following for nixpkgs is correctly configured.


21-42: LGTM!

The supported systems list covers all major platforms, and the forEachSupportedSystem helper correctly applies the default overlay to provide rustToolchain to all system-specific outputs.


50-72: LGTM!

The dev shell provides the Rust toolchain with proper environment configuration. The RUST_SRC_PATH is correctly set for rust-analyzer, and the shell hook provides useful feedback.


75-87: LGTM!

The package output correctly uses crane's buildPackage with the custom Rust toolchain. The source path configuration with builtins.path provides a clean name for the derivation.


90-104: LGTM!

The overlay provides a comprehensive Rust toolchain from fenix's stable channel, including all essential tools (cargo, clippy, rustc, rustfmt, rust-src, rust-analyzer). The combine function properly merges these components into a single rustToolchain derivation.

rust/.envrc (1)

1-1: LGTM!

Standard direnv configuration for flake-based development environments.

rust/Cargo.toml (1)

4-4: Rust edition 2024 is stable and supported. Shipped with Rust 1.85.0 on February 20, 2025.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
rust/flake.nix (2)

13-13: Consider adding inputs.nixpkgs.follows for crane.

The fenix input follows the main nixpkgs input (line 10), but crane does not. This means crane will evaluate its own copy of nixpkgs, leading to unnecessary duplication and slower evaluation times.

Apply this diff to make crane follow the main nixpkgs input:

-    crane.url = "https://flakehub.com/f/ipetkov/crane/0";
+    crane = {
+      url = "https://flakehub.com/f/ipetkov/crane/0";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };

90-93: Consider using crane's source filtering.

Using builtins.path { path = ./.; } includes the entire directory in the Nix store, potentially including build artifacts, editor files, and other unwanted content. Crane provides built-in source filtering that automatically excludes non-Rust files.

Apply this diff to use crane's source filtering:

             default = pkgs.craneBuild.buildPackage {
               pname = meta.name;
               inherit (meta) version;
-              src = builtins.path {
-                name = "${meta.name}-source";
-                path = ./.;
-              };
+              src = pkgs.craneBuild.cleanCargoSource ./.;
             };

This will automatically filter out non-Rust files while keeping Cargo.toml, Cargo.lock, and src/ directory, resulting in a cleaner and smaller Nix store path.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 389a5dc and f4006ed.

📒 Files selected for processing (1)
  • rust/flake.nix (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: checks
🔇 Additional comments (2)
rust/flake.nix (2)

50-81: LGTM!

The development shell configuration is well-structured with:

  • Essential tools (rustToolchain, rust-analyzer)
  • Helpful optional tools documented as comments
  • Proper RUST_SRC_PATH environment variable for rust-analyzer
  • Informative shell hook

99-114: LGTM!

The overlay structure is correct:

  • Properly uses rec to enable forward reference from craneBuild to rustToolchain
  • Correctly overrides crane's toolchain with the custom fenix-based toolchain
  • Combines all necessary Rust stable components (cargo, clippy, rustc, rustfmt, rust-src)

@lucperkins lucperkins requested a review from edolstra October 15, 2025 03:53
@lucperkins lucperkins merged commit f429424 into main Oct 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants